#include <cmath>
#include <iostream>
#include <vector>

/**
 * Luogu P1279 String Distance
 * I did not work out this problem myself. I cannot figure out how to ensure
 * that the two extended string have identical lengths. Actually, this property
 * is guaranteed during state transition. This problem is quite similar to Edit
 * Distance problem.
 */

int main() {
    // Input
    std::string A, B;
    int k;
    std::getline(std::cin, A);
    std::getline(std::cin, B);
    scanf("%d", &k);

    // Use DP to solve the problem
    std::vector<std::vector<int> > buf(A.length() + 1,
                                       std::vector<int>(B.length() + 1));
    for (int i = 0; i <= A.length(); i++) buf[i][0] = k * i;
    for (int i = 1; i <= B.length(); i++) buf[0][i] = k * i;
    for (int i = 1; i <= A.length(); i++) {
        for (int j = 1; j <= B.length(); j++) {
            int l1 = buf[i - 1][j] + k, l2 = buf[i][j - 1] + k;
            int l3 = buf[i - 1][j - 1] + std::abs(A[i - 1] - B[j - 1]);
            buf[i][j] = std::min(l1, std::min(l2, l3));
        }
    }
    printf("%d\n", buf[A.length()][B.length()]);

    return 0;
}